<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>注册一个用 PHP 类实现的 URL 封装协议</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stream-supports-lock.html">stream_supports_lock</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stream-wrapper-restore.html">stream_wrapper_restore</a></div>
 <div class="up"><a href="ref.stream.html">Stream 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.stream-wrapper-register" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">stream_register_wrapper</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">stream_register_wrapper</span> &mdash; <span class="dc-title">注册一个用 PHP 类实现的 URL 封装协议</span></p>

   </div>
   <div class="refsect1 unknown-seealsp" id="refsect1-function.stream-wrapper-register-unknown-seealsp">
    <h3 class="title">说明</h3>
    <div class="methodsynopsis dc-description">
     <span class="type">boolean</span> <span class="methodname"><strong>stream_register_wrapper</strong></span>
      ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$protocol</code></span>
     , <span class="methodparam"><span class="type">string</span> <code class="parameter">$classname</code></span>
     )</div>

    <p class="para rdfs-comment">
     <span class="function"><strong>stream_register_wrapper()</strong></span>
     允许用户实现自定义的协议处理器和流，用于所有其它的文件系统函数中（例如
     <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span>，<span class="function"><a href="function.fread.html" class="function">fread()</a></span> 等）。
    </p>
    <p class="para">
     要实现一个封装协议，需要按照如下定义声明一个包含有一些函数的类。当有人对你的流使用
     fopen 时，PHP 将创建一个 <em><code class="parameter">classname</code></em>
     的实例并调用该实例的方法。必须严格按照如下的描述实现方法 - 否则将导致不明确的行为。
    </p>
    <p class="para">
     如果 <em><code class="parameter">protocol</code></em>
     已经有了处理协议，则 <span class="function"><strong>stream_register_wrapper()</strong></span>
     将返回 <strong><code>FALSE</code></strong>。
    </p>

    <div class="methodsynopsis dc-description">
     <span class="type">boolean</span> <span class="methodname"><strong>stream_open</strong></span>
      ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$path</code></span>
     , <span class="methodparam"><span class="type">string</span> <code class="parameter">$mode</code></span>
     , <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code></span>
     , <span class="methodparam"><span class="type">string</span> <code class="parameter">$opened_path</code></span>
     )</div>

    <p class="para rdfs-comment">
     当你的流对象被创建之后立即会调用此方法。<em><code class="parameter">path</code></em>
     指定了传入 <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> 以及此对象需要取回的 URL。可以用
     <span class="function"><a href="function.parse-url.html" class="function">parse_url()</a></span> 来将此 URL 分割成几部分。
    </p>
    <p class="para">
     <em><code class="parameter">mode</code></em> 用来打开文件的模式，和
     <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> 中的一样。你有责任检查
     <em><code class="parameter">mode</code></em> 对于所请求的
     <em><code class="parameter">path</code></em> 是否合法。
    </p>
    <p class="para">
     <em><code class="parameter">options</code></em> 保存了通过流 API
     设定的附加标志。可以保存以下一个值或者用 OR 合并的多个值。
     <table class="doctable informaltable">
      
       <thead>
        <tr>
         <th>标志</th>
         <th>说明</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>STREAM_USE_PATH</td>
         <td>如果 <em><code class="parameter">path</code></em> 是相对路径，则用
         include_path 搜索资源。
         </td>
        </tr>

        <tr>
         <td>STREAM_REPORT_ERRORS</td>
         <td>如果设定了本标志，你有责任在打开流时用 <span class="function"><a href="function.trigger-error.html" class="function">trigger_error()</a></span>
         来唤起错误。如果没有设定这个标志，那么你不需要唤起任何错误。
         </td>
        </tr>

       </tbody>
      
     </table>

    </p>
    <p class="para">
     如果成功打开了 <em><code class="parameter">path</code></em>，并且在 <em><code class="parameter">options</code></em>
     中设定了 STREAM_USE_PATH，你需要将 <em><code class="parameter">opened_path</code></em>
     设定为实际被打开的文件／资源的完整路径。
    </p>
    <p class="para">
     如果成功打开了所请求的资源，应该返回
     <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
    </p>

    <div class="methodsynopsis dc-description">
     <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>stream_close</strong></span>
      ( <span class="methodparam"><span class="type"><span class="type void">void</span></span></span>
     )</div>

    <p class="para rdfs-comment">
     本方法在流关闭时被调用，使用
     <span class="function"><a href="function.fclose.html" class="function">fclose()</a></span>。必须释放被流锁定或分配的任何资源。
    </p>

    <div class="methodsynopsis dc-description">
     <span class="type">string</span> <span class="methodname"><strong>stream_read</strong></span>
      ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$count</code></span>
     )</div>

    <p class="para rdfs-comment">
     当对流进行 <span class="function"><a href="function.fread.html" class="function">fread()</a></span> 和 <span class="function"><a href="function.fgets.html" class="function">fgets()</a></span> 
     操作时本方法被调用。必须从当前读写位置以字符串返回最多
     <em><code class="parameter">count</code></em> 字节的数据。如果可用数据少于 <em><code class="parameter">count</code></em>
     字节，则返回尽可能多的数据。如果没有可供返回的数据，返回 <strong><code>FALSE</code></strong>
     或者空字符串。必须用成功读取的字节数去更新流的读写位置。
    </p>

    <div class="methodsynopsis dc-description">
     <span class="type">int</span> <span class="methodname"><strong>stream_write</strong></span>
      ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
     )</div>

    <p class="para rdfs-comment">
     当对流进行 <span class="function"><a href="function.fwrite.html" class="function">fwrite()</a></span>
     操作时本方法被调用。必须将 <em><code class="parameter">data</code></em>
     储存到你的流使用的底层存储空间去。如果没有足够的空间了，则试着保存尽可能多的字节。应该返回成功被保存入流的字节数，或者没有保存时返回
     0。必须用成功写入的字节数去更新流的读写位置。
    </p>
   
    <div class="methodsynopsis dc-description">
     <span class="type">boolean</span> <span class="methodname"><strong>stream_eof</strong></span>
      ( <span class="methodparam"><span class="type"><span class="type void">void</span></span></span>
     )</div>

    <p class="para rdfs-comment">
     当对流进行 <span class="function"><a href="function.feof.html" class="function">feof()</a></span>
     操作时本方法被调用。如果读写位置到了流的尽头或者没有更多数据可读时返回
     <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
    </p>

    <div class="methodsynopsis dc-description">
     <span class="type">int</span> <span class="methodname"><strong>stream_tell</strong></span>
      ( <span class="methodparam"><span class="type"><span class="type void">void</span></span></span>
     )</div>

    <p class="para rdfs-comment">
     当对流进行 <span class="function"><a href="function.ftell.html" class="function">ftell()</a></span>
     操作时本方法被调用。应该返回流的当前读写位置。
    </p>

    <div class="methodsynopsis dc-description">
     <span class="type">boolean</span> <span class="methodname"><strong>stream_seek</strong></span>
      ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code></span>
     , <span class="methodparam"><span class="type">int</span> <code class="parameter">$whence</code></span>
     )</div>

    <p class="para rdfs-comment">
     当对流进行 <span class="function"><a href="function.fseek.html" class="function">fseek()</a></span>
     操作时本方法被调用。应该根据 <em><code class="parameter">offset</code></em> 和
     <em><code class="parameter">whence</code></em> 来更新流的读写位置。这些参数的更多信息见
     <span class="function"><a href="function.fseek.html" class="function">fseek()</a></span>。如果位置成功更新了则返回 <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
    </p>

    <div class="methodsynopsis dc-description">
     <span class="type">boolean</span> <span class="methodname"><strong>stream_flush</strong></span>
      ( <span class="methodparam"><span class="type"><span class="type void">void</span></span></span>
     )</div>

    <p class="para rdfs-comment">
     当对流进行 <span class="function"><a href="function.fflush.html" class="function">fflush()</a></span>
     操作时本方法被调用。如果你在流中缓存了数据还没有写入底层存储空间时，那现在应该做了。如果缓存数据被成功保存（或没有数据可供保存）时返回
     <strong><code>TRUE</code></strong>，当数据无法被保存时返回 <strong><code>FALSE</code></strong>。
    </p>

    <p class="para">
     下面的例子实现了一个 var://
     协议处理器，可以允许使用标准的文件系统流函数来对指定的全局变量进行读写操作，例如
     <span class="function"><a href="function.fread.html" class="function">fread()</a></span>。var:// 协议的实现如下，给出
     url &quot;var://foo&quot; 将可以读写 $GLOBALS[&quot;foo&quot;]。

     <div class="example" id="example-3947"> 
      <p><strong>Example #1 读写全局变量的流</strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
class&nbsp;VariableStream&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;$position;<br />&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;$varname;<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;stream_open($path,&nbsp;$mode,&nbsp;$options,&nbsp;&amp;$opened_path)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$url&nbsp;=&nbsp;parse_url($path);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;varname&nbsp;=&nbsp;$url["host"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;position&nbsp;=&nbsp;0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;stream_read($count)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ret&nbsp;=&nbsp;substr($GLOBALS[$this-&gt;varname],&nbsp;$this-&gt;position,&nbsp;$count);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;position&nbsp;+=&nbsp;strlen($ret);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$ret;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;stream_write($data)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$left&nbsp;=&nbsp;substr($GLOBALS[$this-&gt;varname],&nbsp;0,&nbsp;$this-&gt;position);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$right&nbsp;=&nbsp;substr($GLOBALS[$this-&gt;varname],&nbsp;$this-&gt;position&nbsp;+&nbsp;strlen($data));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$GLOBALS[$this-&gt;varname]&nbsp;=&nbsp;$left&nbsp;.&nbsp;$data&nbsp;.&nbsp;$right;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;position&nbsp;+=&nbsp;strlen($data);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;strlen($data);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;stream_tell()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$this-&gt;position;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;stream_eof()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$this-&gt;position&nbsp;&gt;=&nbsp;strlen($GLOBALS[$this-&gt;varname]);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;stream_seek($offset,&nbsp;$whence)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch($whence)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;SEEK_SET:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($offset&nbsp;&lt;&nbsp;strlen($GLOBALS[$this-&gt;varname])&nbsp;&amp;&amp;&nbsp;$offset&nbsp;&gt;=&nbsp;0)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;position&nbsp;=&nbsp;$offset;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;<br />&nbsp;&nbsp;&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nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />stream_register_wrapper("var",&nbsp;"VariableStream")<br />&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;die("Failed&nbsp;to&nbsp;register&nbsp;protocol");<br /><br />$myvar&nbsp;=&nbsp;"";<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />$fp&nbsp;=&nbsp;fopen("var://myvar",&nbsp;"r+");<br /><br />fwrite($fp,&nbsp;"line1\n");<br />fwrite($fp,&nbsp;"line2\n");<br />fwrite($fp,&nbsp;"line3\n");<br /><br />rewind($fp);<br />while(!feof($fp))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;fgets($fp)<br />}<br />fclose($fp);<br />var_dump($myvar);</span>
</code></div>
      </div>

     </div>
    </p>
  
   </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stream-supports-lock.html">stream_supports_lock</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stream-wrapper-restore.html">stream_wrapper_restore</a></div>
 <div class="up"><a href="ref.stream.html">Stream 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
